home *** CD-ROM | disk | FTP | other *** search
- /*
-
- an example of installing a mouse handler via int33
-
- Copyright 1995 Alexander J. Russell
- Placed in the public domain.
-
- */
-
- short mouse_x, mouse_y;
- short mouse_present;
- short mouse_hidden=0;
- short button_stat=0;
- USHORT flags;
-
-
- /* the low level interrupt handler calls this */
- /* ---------------------- mouse_handler() ----------------- April 1,1993 */
- void far interrupt mouse_handler(void)
- {
-
- /* save info returned by mouse device driver */
- asm {
- mov flags, ax
- mov mouse_x, cx
- mov mouse_y, dx
- mov button_stat, bx
- }
-
-
- /*
-
- add your code here to actually do something with the mouse info
-
- check flags for type of mouse event
-
-
- */
- }
-
-
- /*
-
- the assembler function mouse_int() calls
- mouse_event_func whenever the mouse moves, or a button
- is pressed, or released. mouse_event_func points to mouse_handler
- which ques up the mouse events, get_event can be used to read these
- events.
-
- */
-
- /* is there a mouse, install int handlers */
- /* ---------------------- init_mouse() -------------------- April 1,1993 */
- short init_mouse(void)
- {
- USHORT c_seg, c_off;
-
- asm {
- xor ax, ax
- int 033h
-
- /* note BX holds number of buttons, but we don't care */
- mov mouse_present, ax
- }
-
- if ( mouse_present )
- {
- /* install our own handler */
- mouse_event_func=mouse_handler; /* global func pointer */
-
- want_mouse_moves=0;
-
- /* install mouse_int as mouse handler, which will call
- mouse_handler */
-
- c_seg=FP_SEG(mouse_int);
- c_off=FP_OFF(mouse_int);
- asm {
- mov ax, c_seg
- mov es, ax
- mov dx, c_off
- mov ax, 0ch
- mov cx, EVENT_MASK
-
- int 033h
- }
-
- /* set mouse x, y limits */
- asm {
- mov ax, 7
- mov cx, 0
- mov dx, 359
-
- int 033h
-
- mov ax, 8
- mov cx, 0
- mov dx, 239
-
- int 033h
-
-
- /* set initial mouse_x, mouse_y */
- mov ax, 3
- int 033h
-
- mov mouse_x, cx
- mov mouse_y, dx
- }
- }
-
- return(mouse_present);
- }
-
-
-
- /* ---------------------- set_max_mouse() ------------------ May 19,1993 */
- void set_max_mouse(short max_x, short max_y)
- {
- /* set mouse x, y limits */
- asm {
- mov ax, 7
- mov cx, 0
- mov dx, max_x
-
- int 033h
-
- mov ax, 8
- mov cx, 0
- mov dx, max_y
-
- int 033h
- }
-
- }
-
-
- /* ---------------------- deinit_mouse() ------------------ April 1,1993 */
- void deinit_mouse(void)
- {
-
- if ( mouse_present )
- {
- /* deinstall our mouse handler by making int 33 never call it */
- asm {
- mov ax, 0ch
- xor cx, cx /* mask == 0, handler never called */
-
- int 033h
-
- /* reset mouse driver */
- xor ax, ax
- int 033h
- }
- }
- }
-
- /*
-
- the asm part
-
- */
-
-
- ;***************************************************************
- ;* *
- ;* File: cmousea.asm *
- ;* *
- ;* Assembly language hook for CMOUSE library event handler *
- ;* Assemble with /Ml switch *
- ;* *
- ;***************************************************************
- ; real code for real men
- ; adjust for proper memory model
- .MODEL SMALL,C
-
- .CODE
- PUBLIC mouse_event_func,mouse_int
-
- mouse_event_func DD ?
-
-
- mouse_int PROC FAR
- PUSHF
- CALL CS:[mouse_event_func]
- RET
- mouse_int ENDP
-
- END
-